/*
 * Created by SharpDevelop.
 * User: phtrung
 * Date: 1/25/2010
 * Time: 5:48 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using popLib;
using System.IO;
using System.Diagnostics;
using System.Data;

namespace StartupManager
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		
		
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			dgv_files.DataSource = Global.Instance().ApplicationSrc;
		}
		
		void Button1Click(object sender, EventArgs e)
		{
			ReturnSet rs = browseForFile(null);
			if( rs.Success )
				Global.Instance().addItem( rs.Result.ToString() );
		}
		
		
		
		
		
		ReturnSet browseForFile(string updateFile){
			return FormLib.openFile(null,updateFile);
		}
		
		void CellButtonClick(object sender, DataGridViewCellEventArgs e)
		{
			string file = dgv_files.Rows[e.RowIndex].Cells[2].Value.ToString();
			switch( e.ColumnIndex ){
				case 3: 
					ReturnSet rs = browseForFile(file);
					if( rs.Success ) Global.Instance().addItem( rs.Result.ToString(), e.RowIndex );
					break;
				case 4: 
					dgv_files.Rows.RemoveAt(e.RowIndex);
					break;
				case 5: 
						if( File.Exists(file)){
					   		Process.Start(file);
					   	}
					break;
			}
		}
		
		void MainFormFormClosing(object sender, FormClosingEventArgs e)
		{
			Global.Instance().save();
		}
	}
}
